package com.terios.logic.ui;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.terios.R;
import com.terios.Status;
import com.terios.http.WeiboResponse;
import com.weibo.net.WeiboException;

/**  
 * WriteWeibo.java
 * 2012-10-15 下午6:20:56
 * @author Wang Tengrui  
 */
public class WriteWeibo extends Activity {

	ImageView back;// 返回键
	Button send;// 发送键
	EditText etWeiboEditText;// 微博信息
	LinearLayout updatelay;// 状态布局
	
	@SuppressWarnings("static-access")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		requestWindowFeature(getWindow().FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_write);
		back = (ImageView)findViewById(R.id.title_bt_left);
		back.setImageResource(R.drawable.title_back);
		send = (Button)findViewById(R.id.title_bt_right);
		etWeiboEditText = (EditText) this.findViewById(R.id.etWeibo);
		back.setOnClickListener(listener);
		send.setOnClickListener(listener);
		updatelay = (LinearLayout) this.findViewById(R.id.linear_progress);
	}
	private OnClickListener listener = new OnClickListener() {
		
		@SuppressWarnings("unused")
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.title_bt_left:
				WriteWeibo.this.finish();
				break;
			case R.id.title_bt_right:
				String etWeiboString = etWeiboEditText.getText().toString();
				if (!TextUtils.isEmpty(etWeiboString)) {
				//发送 进度布局
				updatelay.setVisibility(View.VISIBLE);
				String source = null;
				String lon = null;
				String lat = null;
				//获取EditText中用户写的微博内容
				
				WeiboResponse mWeiboResponse = WeiboResponse.getInstance(WriteWeibo.this);
				try {
					Status status =new Status(mWeiboResponse.update(source, etWeiboString, lon, lat));
					if (null != status) {
						Toast.makeText(WriteWeibo.this, "发送成功", Toast.LENGTH_SHORT).show();
						WriteWeibo.this.finish();
					}else {
						updatelay.setVisibility(View.GONE);
						Toast.makeText(WriteWeibo.this, "发送错误.", Toast.LENGTH_SHORT).show();
					}
				} catch (WeiboException e) {
					e.printStackTrace();
				}
				}else{
					Toast.makeText(WriteWeibo.this, "发送内容不能为空", Toast.LENGTH_SHORT).show();
				}
				break;
			}
		}
	};

}
